-
Notifications
You must be signed in to change notification settings - Fork 440
[CompilerPlugin] Remove Foundation dependency #2598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci Please test Windows |
38e6d49
to
7fbf536
Compare
swiftlang/swift#73010 |
ed1384b
to
ccc6f9b
Compare
abe880f
to
694c846
Compare
Inspired by swift-foundation's JSONEncoder/JSONDecoder. But basically a re-implementation of Encoder / Decoder.
Instead, use read(2) and write(2) via Darin/Glibc/UCRT
* Rename PluginMessageJSON to JSON * Make JSON encoder/decoder SPI * Make encoding/decoding internals private
Use DecodingError / EcodingError properly
If read(2) returned 0, STDIN is closed. So return nil from 'waitForNextMessage()' so the caller can exit cleanly.
Add _CShims module. For CMake it's a INTERFACE library.
Speculative fix for Windows
8ffdc15
to
5250447
Compare
cd01261
to
501f454
Compare
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
mutating func closeCollection(handle: Int) { | ||
// 'handle': descriptor index. | ||
// 'handle+1': counter index. | ||
mapData[handle + 1] = mapData.count - handle - 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to - 2
here. Only usage (i.e. JSONMapValue.mapSize
) is doing + 2
. Let's just store the mapSize
value, so mapSize
can return the stored value as-is.
There's no reason to '- 2'/'+ 2'.
* typo * Remove unnecessary withExtendedLifetime() * remove JSONObject.subscript(_:) as it's not O(1) * Use 'LosslessStringConvertible'
* Don't use UTF8 decoder for decoding escaped strings * Only memcmp ASCII non-escaped strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general. Don’t be distracted by the truckload of comments that I’m leaving here. I think most are nitpicky, just a few correctness questions.
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
Update for review comments
7d7902c
to
197a45c
Compare
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
e02a7a0
to
a684b3b
Compare
guard case .array(var arr) = backing else { | ||
preconditionFailure() | ||
} | ||
backing = .null // Ensure 'err' uniquely referenced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick 😉
backing = .null // Ensure 'err' uniquely referenced. | |
backing = .null // Ensure 'arr' uniquely referenced. |
Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only open discussion is why we needed to define compareMemory
for SyntaxText
but can unconditionally use memcmp
here: #2598 (comment)
Update for review comments
Use 'for' look instead of 'while cursor != end { cursor += 1 }'
The source JSON buffer is not guaranteed to be null terminated. If a number is at top-level, 'strtod'/'strtof' tries to read past the buffer which is not great
Avoid possible module name collision
a684b3b
to
1e2c3bd
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test Windows |
read(2)
/write(2)
instead ofFoundation.FileHandle
rdar://126714084